<?php
header('content-type:text/html;charset=utf-8');
require_once 'application/core/functions.php';
require_once 'application/core/BaseController.php';
require_once 'application/core/BaseModel.php';
require_once 'application/core/PublicController.php';
require_once 'application/core/page.class.php';
session_start();
$controller = isset($_GET['c']) && !empty($_GET['c']) ? $_GET['c'].'Controller' : null;
$action = isset($_GET['a']) && !empty($_GET['a']) ? $_GET['a'].'Action' : null;

if(empty($controller) || empty($action)){
    $uri = $_SERVER['REQUEST_URI'];
    $url = explode('/', $uri);
    $index = -1;
    foreach ($url as $k=>$v){
        if($v == 'index.php'){
            $index = $k;
            break;
        }
    }
    if($index == -1){
        $controller = 'indexController';
        $action = 'indexAction';
    }else {
        if(isset($url[$index+1]) && !empty($url[$index+1])){
            $controller = $url[$index+1].'Controller';
            $action_arr = explode('-', str_replace('.html', '', $url[$index+2]));
            $action = array_shift($action_arr).'Action';
            if(count($action_arr >= 2)){
                foreach ($action_arr as $key=>$vv){
                    if($key % 2 == 0 && isset($action_arr[$key + 1])){
                        $_GET[$vv] = $action_arr[$key + 1];
                    }
                }
            }
        }else {
            $controller = 'indexController';
            $action = 'indexAction';
        }
    }  
}
define('ROOT', '/News/');
define('APP', ROOT.'index.php');
require_once 'application/controller/'.$controller.'.php';
$controller_ob = new $controller();
$controller_ob->$action();